<template>
    <orh-table pages :pageDate="pageDate" @on-page-change="changepage"
               search @on-search='searchblurry' reload @on-reload="refresh">
        <Table slot="table" border :columns="columns" :data="datas"
               ref="currentRowTable" :loading="loading">
        </Table>
        <orh-sidebar slot="others" v-model="modelShow" title="公文审核" scale>
            <review-detail :id="id" @close="modelShow=false" @reload="load" :userId='userId'></review-detail>
        </orh-sidebar>
        <orh-sidebar slot="others" v-model="modelShowedit" title="公文修改" scale>
            <review-edit :id="id" @close="modelShowedit=false" @reload="load" :userId='userId'></review-edit>
        </orh-sidebar>
        <orh-sidebar slot="others" v-model="detailShow" title="公文详情" scale>
            <look-detail :id="id" :lookdetails='lookdetails'></look-detail>
        </orh-sidebar>
    </orh-table>
</template>

<script>

    export default {
        layout: "menu",
        data() {
            return {
                modelShowedit: false,
                lookdetails: false,
                id: '',
                userId: '',
                modelShow: false,
                detailShow: false,
                loading: false,
                pageDate: {
                    total: 0,
                    current_page: 1,
                    per_page: 0
                },
                datas: [],
                columns: [
                    {
                        title: '标题',
                        render: (h, params) => {
                            let document = params.row.document
                            return h('span', document.title.zh || document.title.mn)
                        }
                    },
                    {
                        title: '来文机关',
                        render: (h, params) => {
                            let document = params.row.document
                            return h('span', document.civil_service.zh || document.civil_service.mn)
                        }
                    },
                    {
                        title: '来文字号',
                        render: (h, params) => {
                            let document = params.row.document
                            return h('span', document.letter_number.zh || document.letter_number.mn)
                        }
                    },
                    {
                        title: '收文时间',
                        render: (h, params) => {
                            let document = params.row.document
                            return h('span', document.receipt_time)
                        }
                    },
                    {
                        title: '等级文号',
                        render: (h, params) => {
                            let document = params.row.document
                            return h('span', document.document_code)
                        }
                    },
                    {
                        title: '等级',
                        render: (h, params) => {
                            let document = params.row.document
                            return h('span', document.grade.zh || document.grade.mn)
                        }
                    },
                    {
                        title: '类型',
                        render(h, params) {
                            let document = params.row.document
                            return h('span', document.dictionary.dictionary_name.zh || document.dictionary.dictionary_name.mn)
                        }
                    },
                    {
                        title: '拟办意见',
                        render: (h, params) => {
                            let document = params.row.document
                            return h('span', document.options.zh || document.options.mn)
                        }
                    },
                    {
                        title: '审核状态',
                        render(h, params) {
                            let str = ''
                            let color = ''
                            switch (params.row.status) {
                                case 0:
                                    str = '未审核'
                                    color = '#007d7f'
                                    break;
                                case 1:
                                    str = '通过审核'
                                    color = '#19be6b'
                                    break;
                                case 2:
                                    str = '未通过审核'
                                    color = '#ed3f14'
                                    break;
                                case 3:
                                    str = '已向上级提交'
                                    color = '#ed3f14'
                                    break;
                            }
                            return h('span', {style: {color}}, str)
                        }
                    },
                    {
                        title: '操作',
                        key: 'operation',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'success',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px',
                                    },
                                    on: {
                                        click: () => {
                                            this.detailShow = true
                                            this.id = params.row.document_id
                                        }
                                    }
                                }, '查看'),
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small',
                                    },
                                    style: {
                                        marginRight: '5px',
                                        display: params.row.status == 0 || params.row.status == 2 ? '' : 'none',
                                    },
                                    on: {
                                        click: () => {
                                            this.toShows(params.row)
                                        }
                                    }
                                }, '审核'),
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small',
                                    },
                                    style: {
                                        marginRight: '5px',
                                        display: params.row.status == 1 || params.row.status == 2 ? '' : 'none',
                                    },
                                    on: {
                                        click: () => {
                                            this.toShowsedit(params.row)
                                        }
                                    }
                                }, '修改')
                            ])
                        }
                    }
                ],
                auditUrl: 'api/document/v1/document/access/',
                url: 'api/document/v1/document/my_examine',
                pageUrl: 'api/document/v1/document/my_examine?page='
            }
        },
        methods: {
            load() {
                this.$http.get(this.url).then(val => {
                    const page = {
                        current_page: val.current_page,
                        current_page: val.current_page,
                        first_page_url: val.first_page_url,
                        from: val.from,
                        last_page: val.last_page,
                        last_page_url: val.last_page_url,
                        next_page_url: val.next_page_url,
                        path: val.path,
                        per_page: val.per_page,
                        prev_page_url: val.prev_page_url,
                        to: val.to,
                        total: val.total
                    }
                    this.pageDate = page
                    this.datas = val.data.data
                }).catch(
                    err => console.log(err)
                )
            },
            //搜索
            searchblurry(val) {
                this.loading = true
                let value = 1
                this.$http.get('api/document/v1/document/my_examine?searchvalue=' + val + '&page=' + value).then(val => {
                    if (val.code == 200) {
                        this.pageSize = val.data.per_page
                        this.dataCount = val.data.total
                        this.current = val.data.current_page
                        this.datas = val.data.data
                    }
                    this.loading = false
                }, err => console.log(err))
            },
            //刷新
            refresh() {
                this.changepage(this.pageDate.current_page)
            },
            toShows(item) {
                this.modelShow = true
                this.id = item.document_examine_id
                this.userId = item.user
            },
            toShowsedit(item) {
                this.modelShowedit = true
                this.id = item.document_examine_id
                this.userId = item.user
            },
            changepage(index) {
                this.loading = true
                this.$http.get(this.pageUrl + index).then(val => {
                    this.pageSize = val.data.per_page
                    this.dataCount = val.data.total
                    this.current = val.data.current_page
                    this.datas = val.data
                    this.loading = false
                }, err => console.log(err))
            },
        },
        components: {
            ReviewDetail: re => require(['./Review.vue'], re),
            LookDetail: re => require(['./../DocumManage/DocmDtail.vue'], re),
            ReviewEdit: re => require(['./ReviewEdit.vue'], re),
        },
        created() {
            this.load()
        }
    }
</script>
